﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CobraCms.AdminConsole.Core.Interfaces;
using Newtonsoft.Json;
using System.Web;

namespace CobraCms.AdminConsole.Core
{
    public class AdminRequestContext
    {
        private List<IAdminUiTask> _uiTasks = new List<IAdminUiTask>();

        private AdminRequestContext()
        {
        }

        public static AdminRequestContext Instance
        {
            get
            {
                var instance = HttpContext.Current.Items["CobraAdminRequestContext"] as AdminRequestContext;
                if (instance == null)
                {
                    instance = new AdminRequestContext();
                    HttpContext.Current.Items["CobraAdminRequestContext"] = instance;
                }
                return instance;
            }
        }

        public void AddAdminUiTask(IAdminUiTask task)
        {
            _uiTasks.Add(task);
        }

        public string GetJsonTaskList()
        {
            return JsonConvert.SerializeObject(_uiTasks);
        }
    }
}
